<?php
defined('IN_PHPCMS') or exit('No permission resources.');
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_sys_class('model', '', 0);
class reg_table_column_model extends model {
	public function __construct() {
		$this->db_config = pc_base::load_config('database');
		$this->db_setting = 'default';
		$this->table_name = 'reg_table_column';
		parent::__construct();
	}

	/**
	 * 添加修改
	 */
	public function edit ($data,$id='')
	{
		$data = $this->check($data);
		if (!$id) {
			$id = $this->insert($data, true);
		} else {
			$ids = $this->update($data, array('id'=>$id));
		}
		return $id;
	}

	/**
	 * 表单验证
	 *
	 * @param array $data
	 *            表单传递的值
	 * @param string $a
	 *            add/edit添加操作时，自动加上默认值
	 */
	public function check($data, $a = 'add')
	{
		$data['is_accord'] = $data['is_show'] == 1?$data['is_accord']:0;
		if ($a == 'add') {
			$data['siteid'] = get_siteid();;
			$data['create_time'] =date("Y-m-d H:i:s",time());
			$data['created_by'] = $_SESSION['userid'];
			$data['update_time'] =date("Y-m-d H:i:s",time());
			$data['updated_by'] = $_SESSION['userid'];
		} else {
			$data['update_time'] =date("Y-m-d H:i:s",time());
			$data['updated_by'] = $_SESSION['userid'];
		}
		return $data;
	}
}
?>